<?php
/**
 * Created by PhpStorm.
 * User: 王文文
 * Date: 2017/5/15
 * Time: 21:20
 */

namespace frontend\controllers;


use yii\web\Controller;
use yii\web\AesEncrypt;
class CommonController extends Controller{
//    public function init(){
//        parent::__construct();
//
//        //过滤参数
//        $_POST = html_encode( $_POST );
//
//        $_GET = html_encode( $_GET );
//
//        $_REQUEST = html_encode( $_REQUEST );
//
//    }
    /**
     * @param $data
     * @return array
     * 数据加密
     */


    public function buildParams($data)
    {
//        $res = new AesEncrypt();
        //拼接调用接口的App_id和App_key
        $param = [
            'app_id'  =>2,
        ];

        //对数组进行有序的排序
        ksort($data);

        //生成签名
        $param['sign'] = md5(json_encode($data).'123456');

        //加密传输数据
        $param['data'] = AesEncrypt::encrypt(json_encode($data));

        return $param;
    }


}